const XEUtils = require('xe-utils')

/**
 * Mainly used for data list paging url param handle
 * @param getListApi => api function(required)
 */

export default {
  data() {
    return {
      layout: 'total, sizes, prev, pager, next, jumper',
      total: 1,
      pageSizeOptions: [10, 30, 50],
      listLoading: false,
      pageParams: {
        limit: 10,
        page: 1,
      }
    }
  },
  mounted() {
    this.debounceGET()
  },
  methods: {
    resetClick(val) {
      // 重置
      if (JSON.stringify(this[val]) === '{}') return
      this.clearParams(val)
    },
    clearParams(val) {
      this[val] = {}
      this.pageParams = {
        limit: 10,
        page: 1,
      }
      this.debounceGET()
    },
    pageFun(val) {
      // 分页
      this.pageParams.limit = val
      this.debounceGET()
    },
    pageSizeFun(val) {
      // 改变size
      this.pageParams.page = val
      this.debounceGET()
    },
    debounceGET: XEUtils.debounce(function () {
      this.getListApi()
    }, 100, {
      leading: false,
      trailing: true
    })
  }
}
